<template>
  <el-container style="height: 100%">
    <!-- 顶部 -->
    <el-header>
      <div>
        <img src="../../public/favicon.png" alt="test" />
        <span>大渡桥横铁索寒</span>
      </div>
      <el-button type='"info' @click="loginOut"> login out</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse? '64px': '150px'">
        <div class="toggle-button" @click="transform">|||</div>
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          :collapse= "isCollapse"
          :collapse-transition= "false"
          router
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulists"
            :key="item.id"
          >
            <template slot="title">
              <i :class="iconsObj[item.id]" style="margin-right: 10px"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
                :index=" '/' + subItem.path "
                v-for="subItem in item.children"
                :key="subItem.id"
                >
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{ subItem.authName }}</span>
                </template>
            </el-menu-item
              >
            <!-- <el-menu-item-group>
              <el-menu-item index="1-1">选项一</el-menu-item>
              <el-menu-item index="1-2">选项er</el-menu-item>
            </el-menu-item-group> -->
            <!-- <el-submenu index="1-4">
              <template slot="title">选项4</template>
            </el-submenu> -->
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulists: [],
      iconsObj: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-3702mima',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      isCollapse: false
    }
  },
  created() {
    this.getMenuList()
  },
  methods: {
    loginOut() {
      window.sessionStorage.clear()
      this.$router.push('/login')
      this.$message.success('已退出')
    },
    async getMenuList() {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menulists = res.data
    },
    transform() {
      this.isCollapse = !this.isCollapse
    }
  }
}
</script>

<style lang="less" scoped>
.el-header {
  background-color: #2e6d85;
  display: flex;
  justify-content: space-between;
  padding-left: 15px;
  align-items: center;
  font-size: 20px;
  color: white;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #333744;
  height: 100%;
  .el-menu{
    border: 0;
  }
}
.el-main {
  background-color: #eaedf1;
}
.toggle-button{
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
